package leetcode;

/**
 * Created with IntelliJ IDEA.
 * User: Ghost
 * Date: 14-6-11
 * Time: 下午4:11
 * To change this template use File | Settings | File Templates.
 */
public class Single_Number_II {
    public static int singleNumber(int[] A) {
        int ones=0,twos=0,xthrees = 0;
        for(int i=0;i<A.length;i++){
            twos |= (ones & A[i]);
            ones ^= A[i];
            xthrees = ~(ones & twos);
            ones &=xthrees;
            twos &=xthrees;
        }
        return ones;
    }
    public static void main(String[] args){
        int[] A = {1,2,3,3,2,1,1,2,3,5};
        System.out.println(singleNumber(A));
    }
}
